import { Socket } from 'socket.io-client';

// Socket 事件类型定义
export interface SocketEvents {
  // 发送消息相关
  send_message: {
    from: string;
    to: string;
    message: string;
    messageType: string;
    timestamp: Date;
  };

  send_file: {
    from: string;
    to: string;
    fileUrl: string;
    fileName: string;
    fileSize: number;
    messageType: string;
  };

  send_image: {
    from: string;
    to: string;
    imageUrl: string;
    messageType: string;
  };

  send_voice: {
    from: string;
    to: string;
    audioUrl: string;
    duration: number;
    messageType: string;
  };

  send_position: {
    from: string;
    to: string;
    latitude: number;
    longitude: number;
    address: string;
    messageType: string;
  };

  // 接收消息相关
  receive_message: {
    from: string;
    to: string;
    message: string;
    messageType: string;
    timestamp: Date;
  };

  // 用户状态相关
  user_online: {
    username: string;
    timestamp: Date;
  };

  user_offline: {
    username: string;
    timestamp: Date;
  };

  // 语音视频通话相关
  voice_call_request: {
    fromUserId: string;
    fromUserName: string;
    fromUserImage: string;
    offer: RTCSessionDescriptionInit;
  };

  video_call_request: {
    fromUserId: string;
    fromUserName: string;
    fromUserImage: string;
    offer: RTCSessionDescriptionInit;
  };

  voice_call_answered: {
    fromUserId: string;
    answer: RTCSessionDescriptionInit;
  };

  video_call_answered: {
    fromUserId: string;
    answer: RTCSessionDescriptionInit;
  };

  voice_call_rejected: {
    fromUserId: string;
  };

  video_call_rejected: {
    fromUserId: string;
  };

  voice_call_ended: {
    fromUserId: string;
  };

  video_call_ended: {
    fromUserId: string;
  };

  ice_candidate: {
    fromUserId: string;
    candidate: RTCIceCandidateInit;
  };

  call_error: {
    message: string;
  };

  // 连接相关
  connect: void;
  disconnect: void;
  connect_error: Error;
}

// 扩展 Socket 类型以支持我们的事件
export type AppSocket = Socket<SocketEvents>;

// 导出基础 Socket 类型供组件使用
export { Socket };
